package com.orange.app.service.impl;

import java.util.Date;
import java.util.UUID;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import ch.qos.logback.classic.Logger;

import com.orange.app.mapper.OrderDetailMapper;
import com.orange.app.mapper.OrderMapper;
import com.orange.app.model.Order;
import com.orange.app.model.OrderDetail;
import com.orange.app.service.OrderService;
@Service
@Slf4j
public class OrderServiceImpl implements OrderService{
	@Autowired
	private OrderMapper orderMapper;
	
	@Autowired
	private OrderDetailMapper detailMapper;

	@Transactional(propagation = Propagation.REQUIRED)
	public int insertOrder() {
		Order record = new Order();
		String orderno = UUID.randomUUID().toString();
		System.out.println("orderno:"+orderno);
		record.setOrderNo(orderno);
		record.setCreateDate(new Date());
		
		OrderDetail detail = new OrderDetail();
		detail.setOrderNo(orderno);
		detail.setProductName("牛肉干");
		detail.setCreateDate(new Date());
		
		orderMapper.insert(record);
		this.insertOrderDetail(detail);
		int a = 1/0;
//		try{
//			
//			
//		}catch(Exception e){
//			//TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//		}
		
		return 0;
	}
	@Transactional(propagation = Propagation.REQUIRED)
	public void insertOrderDetail(OrderDetail record){
		detailMapper.insert(record);
	}
}
